Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
The bintrees npm package provides data structures for binary search trees, including Red-Black trees and Splay trees. These structures are useful for efficiently storing and retrieving ordered data.
Red-Black Tree
This feature allows you to create and manipulate a Red-Black tree, which is a balanced binary search tree. The code sample demonstrates how to create a Red-Black tree, insert elements, and find an element.
const { RBTree } = require('bintrees');
const tree = new RBTree((a, b) => a - b);
tree.insert(5);
tree.insert(3);
tree.insert(7);
console.log(tree.find(3)); // Output: 3
console.log(tree.size); // Output: 3
Splay Tree
This feature allows you to create and manipulate a Splay tree, which is a self-adjusting binary search tree. The code sample demonstrates how to create a Splay tree, insert elements, and find an element.
const { SplayTree } = require('bintrees');
const tree = new SplayTree((a, b) => a - b);
tree.insert(5);
tree.insert(3);
tree.insert(7);
console.log(tree.find(3)); // Output: 3
console.log(tree.size); // Output: 3
The avl package provides an implementation of AVL trees, which are another type of self-balancing binary search tree. Compared to bintrees, avl focuses specifically on AVL trees, which may offer different performance characteristics depending on the use case.
The js-sdsl package offers a variety of data structures, including Red-Black trees and other balanced trees. It provides a more comprehensive set of data structures compared to bintrees, which focuses specifically on Red-Black and Splay trees.
The functional-red-black-tree package provides an immutable Red-Black tree implementation. This package is useful for functional programming paradigms, offering immutability features that bintrees does not provide.
This package provides Binary and Red-Black Search Trees written in Javascript. It is released under the MIT License.
Binary Search Trees are a good way to store data in sorted order. A Red-Black tree is a variation of a Binary Tree that balances itself.
Algorithms were taken from Julienne Walker: http://eternallyconfuzzled.com/jsw_home.aspx
node.js:
npm install bintrees
var RBTree = require('bintrees').RBTree;
var tree = new RBTree(function(a, b) { return a - b; });
tree.insert(2);
tree.insert(-3);
see examples/node.js for more info
In the browser:
<script src="/path/to/rbtree.js"></script>
<script>
var tree = new RBTree(function(a, b) { return a - b; });
tree.insert(0);
tree.insert(1);
</script>
see examples/client.html for more info
Requires 1 argument: a comparator function f(a,b) which returns:
0 if a > b
Inserts the item into the tree. Returns true if inserted, false if duplicate.
Removes the item from the tree. Returns true if removed, false if not found.
Number of nodes in the tree.
Removes all nodes from the tree.
Returns node data if found, null otherwise.
Returns an iterator to the node if found, null otherwise.
Returns an iterator to the tree node at or immediately after the item. Returns null-iterator if tree is empty.
NOTE: Changed in version 1.0.0 to match C++ lower_bound
Returns an iterator to the tree node immediately after the item. Returns null-iterator if tree is empty.
NOTE: Changed in version 1.0.0 to match C++ upper_bound
Returns the min node data in the tree, or null if the tree is empty.
Returns the max node data in the tree, or null if the tree is empty.
Calls f on each node's data, in order.
Calls f on each node's data, in reverse order.
Returns a null-iterator. See Iterators section below.
tree.iterator() will return a null-iterator. On a null iterator,
Otherwise,
When iteration reaches the end, the iterator becomes a null-iterator again.
Forward iteration example:
var it=tree.iterator(), item;
while((item = it.next()) !== null) {
// do stuff with item
}
If you are iterating forward through the tree, you can always call prev() to go back, and vice versa.
NOTE: iterators become invalid when you add or remove elements from the tree.
FAQs
Binary Search Trees
The npm package bintrees receives a total of 2,087,246 weekly downloads. As such, bintrees popularity was classified as popular.
We found that bintrees demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.